package org.jeecg.modules.bim.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.modules.bim.entity.BimDevs;
import org.jeecg.modules.bim.service.IBimDevsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/bim")
@Api(tags = "bim设备数据")
public class BimDevsController {

    @Autowired
    private IBimDevsService bimDevsService;


    /**
     * 设备数据添加
     *
     * @param projectInfoId
     * @return
     */
    @ApiOperation(value = "设备数据列表查询", notes = "设备数据列表查询")
    @GetMapping(value = "devs/query")
    public Result<List<BimDevs>> queryDevs(@RequestParam @ApiParam("工程管理自增id") Integer projectInfoId) {
        List<BimDevs> bimDevs = bimDevsService.queryDevs(projectInfoId, null);
        return Result.OK(bimDevs);
    }

    /**
     * 设备数据添加
     *
     * @param bimDevs
     * @return
     */
    @AutoLog(value = "设备数据-添加")
    @ApiOperation(value = "设备数据-添加", notes = "设备数据-添加")
    @PostMapping(value = "devs/add")
    public Result<?> addDevs(@RequestBody BimDevs bimDevs) {
        return Result.OK(bimDevsService.addBimDevs(bimDevs));
    }

    /**
     * 设备数据添加
     *
     * @param bimDevs
     * @return
     */
    @AutoLog(value = "设备数据-添加")
    @ApiOperation(value = "设备数据-编辑", notes = "设备数据-编辑")
    @PostMapping(value = "devs/edit")
    public Result<?> editDevs(@RequestBody BimDevs bimDevs) {
        bimDevsService.updateById(bimDevs);
        return Result.OK(bimDevsService.getById(bimDevs.getId()));
    }

    /**
     * 设备数据添加
     *
     * @param id
     * @return
     */
    @AutoLog(value = "设备数据-删除")
    @ApiOperation(value = "设备数据-删除", notes = "设备数据-删除")
    @DeleteMapping(value = "devs/delete")
    public Result<String> delete(@RequestParam Long id) {
        bimDevsService.removeById(id);
        return Result.OK("删除成功！");
    }


}
